import {getGoodsApi} from '../../request/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs:[{
      id:0,
      value:'综合',
      isActive:true
    },{
      id:1,
      value:'销量',
      isActive:false
    },{
      id:2,
      value:'价格',
      isActive:false
    },],
    Querparams:{
      query:"",
      cid:5,
      pagenum:1,
      pagesize:10
    },
    totalpages:5,
    goodsList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    console.log(options.cid);
    this.setData({
        "Querparams.cid":options.cid
    })
      this.getGoodsList()
  },
//   获取商品数据
  getGoodsList(){
    getGoodsApi(this.data.Querparams).then(res=>{
      console.log(res);
      this.setData({
        goodsList:[...this.data.goodsList,...res.message.goods]
      })
    })
  },

  
  tabsChange(e){
    const {index} =e.detail
    let {tabs}=this.data;
    tabs.forEach((item,i)=>i===index?item.isActive=true:item.isActive=false)
    this.setData({
      tabs
    })
  },

})